﻿using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace HomeWork9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            string url = textBox1.Text;
            try
            {
                webBrowser1.Url = new Uri(url);
                webBrowser1.Navigate(url);
                
            }
            catch (WebException webEx)
            {

                Console.WriteLine(webEx.Message.ToString());

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            string url = textBox1.Text;
            string html = wc.DownloadString(url);
            string telPattern = @"^(1)\d{10}$";
            string emailPattern = @"[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\-_]+[a-zA-Z0-9\.]+[a-zA-Z0-9\.]+";
            MatchCollection mc1 = Regex.Matches(html, telPattern);
            foreach (Match match in mc1) textBox2.Text += match.ToString() + '\n';
            MatchCollection mc2 = Regex.Matches(html, emailPattern);
            foreach (Match match in mc2) textBox3.Text += match.ToString() + '\n';
        }
    }
}
